Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Only try to remove deprecated plugins from array expressions #91

Merged
merged 3 commits into from
Mar 21, 2017

Conversation

okonet
Copy link
Contributor

@okonet okonet commented Mar 19, 2017

What kind of change does this PR introduce?
bugfix

Did you add tests for your changes?
Yes

If relevant, did you update the documentation?
N/A

Summary

It fixes #83 and shows a nice error message for unsupported cases:

2017-03-20 at 09 50

Does this PR introduce a breaking change?
Nope

Other information
For now, only plugins instantiated in an array can be removed by deprecated plugins transform since this is safe.

For now only plugins instantiated in an array can be removed since this is safe.
All other usages are considered not safe and thus won't be modified.

- Display a message about the current support

Closes #83
- Pass the source to the transform function
- This allows displaying code snippets in error messages
@@ -37,7 +37,7 @@ function transform(source, transforms, options) {
quote: 'single'
}, options);
transforms = transforms || Object.keys(transformations).map(k => transformations[k]);
transforms.forEach(f => f(jscodeshift, ast));
transforms.forEach(f => f(jscodeshift, ast, source));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for adding source as an option?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, didn't notice!

Copy link
Member

@evenstensberg evenstensberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGMT here, I already assume it works as excepted. Mind posting a screenshot too? Also, look at my comment

@okonet
Copy link
Contributor Author

okonet commented Mar 20, 2017

Updated description with a screenshot.

@evenstensberg
Copy link
Member

Looks good LGTM on my end. Sending to @pksjce to final review.

- Don't use `console.error` to fix colors.
- Use chalk instead to make output more prettier.
- Better error message with an example of the expected usage.
) {
// Check how many plugins are defined and
// if there is only last plugin left remove `plugins: []` node
if (path.parent.value.elements.length === 1) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

safeTraverse these?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point but since I'm checking it's an array before, I think it's not pretty safe. Thoughts?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I meant you could replace all of this with safeTraverse.

const value = safeTraverse(path, ['parent', 'value']);
if (utils.isType(value, 'ArrayExpression')) {
  const len = safeTraverse(value, ['elements', 'length']);
  if (len && len === 1) {
    ...
  } else

@pksjce
Copy link

pksjce commented Mar 21, 2017

@okonet - This will go before #92 right?

@okonet
Copy link
Contributor Author

okonet commented Mar 21, 2017

Yes, it is suppose to go out before merging with #92

// Check how many plugins are defined and
// if there is only last plugin left remove `plugins: []` node
if (path.parent.value.elements.length === 1) {
j(path.parent.parent).remove();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a valid way of removing ast nodes? I did not know at all. I usually come down from the parent and then modify it to remove any node. :(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean by "valid way" but this works exactly as if I would come from the top of the tree.

@pksjce pksjce merged commit d060ad8 into master Mar 21, 2017
@pksjce pksjce deleted the fix/#83-deprecated-plugins branch March 21, 2017 10:10
@okonet
Copy link
Contributor Author

okonet commented Mar 21, 2017

@pksjce ouch you already merged it without waiting for my updates?

@pksjce
Copy link

pksjce commented Mar 21, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

webpack --migrate error
3 participants